
// https://www.npmjs.com/package/delegates

const assert = require('assert');
const delegate = require('delegates');

(function main() {
    test5();
})();

function test5(){
    const obj = {};
    const target = {
        hello(name) {
            return `hello ${name}`;
        }
    };
    obj.foo = target;
    delegate(obj, 'foo').method('hello');
    console.log(obj.hello('Jack'));
}

function test4() {
    const obj = {};

    obj.request = {
        foo: function (bar) {
            assert(this == obj.request);
            return bar;
        }
    };

    delegate(obj, 'request').method('foo');

    console.log(obj.foo('something'));
}

function test3() {
    const obj = {};
    const target = {};
    target.prototype.hello = function (name) {
        console.log(`hello ${name}`);
    };
    delegate(obj, target).method('hello');
    obj.hello('Jack');
}

function test2() {
    const obj = {};
    const target = {};
    target.prototype.hello = (name) => {
        console.log(`hello ${name}`);
    };
    delegate(obj, target).method('hello');
    obj.hello('Jack');
}

function test1() {
    const obj = {};
    const target = {};
    target.hello = (name) => {
        console.log(`hello ${name}`);
    };
    delegate(obj, target).method('hello');
    obj.hello('Jack');
}

